function t(t) {
    return t.substring(1);
}

wx.getSystemInfoSync().windowWidth;

var o = getApp();

Page({
    data: {
        textConfig: {
            text: "",
            color: "#000000",
            size: 40,
            font: 0
        },
        bgConfig: {
            height: 300,
            width: 700,
            color: ""
        },
        dtTextConfig: {
            text: "",
            color: "#000000",
            size: 40,
            font: 0,
            time: 4,
            bgcolor: ""
        },
        bgColorArray: [ "透明背景", "黑色", "白色", "红色", "橙色", "黄色", "绿色", "蓝色", "靛色", "紫色" ],
        bgObColorArray: [ "", "#000000", "#ffffff", "#FF0000", "#FF7D00", "#FFFF00", "#00FF00", "#0000FF", "#00FFFF", "#FF00FF" ],
        fontColorArray: [ "黑色", "白色", "红色", "橙色", "黄色", "绿色", "蓝色", "靛色", "紫色" ],
        fontVaColorArray: [ "#000000", "#ffffff", "#FF0000", "#FF7D00", "#FFFF00", "#00FF00", "#0000FF", "#00FFFF", "#FF00FF" ],
        fontList: [ "思源黑体", "思源宋体", "手写体", "软笔手写", "站酷高端黑", "站酷庆科黄油", "站酷文艺", "站酷小薇logo" ],
        playTime: [ "1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "10s", "11s", "12s", "13s", "14s", "15s" ],
        ad: {}
    },
    onLoad: function(t) {
        this.setData({
            ad: o.globalData.ad
        });
        var e = this;
        wx.showLoading({
            title: "加载字体配置中"
        }), wx.request({
            url: "https://656d-emojimaker-release-7xvun-1301707257.tcb.qcloud.la/json/fontconfig.json",
            headers: {
                "Content-Type": "application/json"
            },
            success: function(t) {
                wx.hideLoading({
                    success: function(t) {}
                }), e.setData({
                    fontList: t.data
                });
            }
        });
    },
    bindBgPickerChange: function(t) {
        var o = this;
        this.setData({
            "bgConfig.color": o.data.bgObColorArray[t.detail.value]
        });
    },
    textToPic: function() {
        var e = this.data.textConfig, a = this.data.bgConfig;
        "" == e.text ? wx.showModal({
            title: "提示",
            content: "请输入文字",
            showCancel: !1
        }) : (wx.showLoading({
            title: "检测文本"
        }), wx.request({
            url: o.globalData.apiUrl + "/checkText",
            data: {
                text: e.text
            },
            success: function(n) {
                if (wx.hideLoading(), n.data.success) {
                    wx.showToast({
                        title: "检查通过"
                    }), wx.showLoading({
                        title: "生成图片"
                    });
                    var i = o.globalData.apiUrl + "/api";
                    wx.downloadFile({
                        url: i + "?text=" + e.text + "&font=" + e.font + "&bgColor=" + t(a.color) + "&textColor=" + t(e.color),
                        success: function(t) {
                            wx.hideLoading(), 200 == t.statusCode ? wx.navigateTo({
                                url: "/pages/preview/preview?imageurl=" + t.tempFilePath
                            }) : wx.showToast({
                                title: "服务器出错，请稍候再试",
                                icon: "none"
                            });
                        },
                        fail: function() {
                            wx.showToast({
                                title: "连接出错",
                                icon: "none"
                            });
                        }
                    });
                } else wx.showToast({
                    title: n.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                wx.hideLoading(), wx.showToast({
                    title: "连接出错",
                    icon: "none"
                });
            }
        }));
    },
    textToGIF: function() {
        var e = this.data.dtTextConfig;
        "" == e.text ? wx.showModal({
            title: "提示",
            content: "请输入文字",
            showCancel: !1
        }) : (wx.showLoading({
            title: "检测文本"
        }), wx.request({
            url: o.globalData.apiUrl + "/checkText",
            data: {
                text: e.text
            },
            success: function(a) {
                if (wx.hideLoading(), a.data.success) {
                    wx.showToast({
                        title: "检查通过"
                    }), wx.showLoading({
                        title: "生成图片"
                    });
                    var n = o.globalData.apiUrl + "/gifapi";
                    wx.downloadFile({
                        url: n + "?text=" + e.text + "&font=" + e.font + "&bgColor=" + t(e.bgcolor) + "&textColor=" + t(e.color) + "&time=" + (parseInt(e.time) + 1),
                        success: function(t) {
                            wx.hideLoading(), 200 == t.statusCode ? wx.navigateTo({
                                url: "/pages/preview/preview?imageurl=" + t.tempFilePath
                            }) : wx.showToast({
                                title: "服务器出错，请稍候再试",
                                icon: "none"
                            });
                        },
                        fail: function() {
                            wx.showToast({
                                title: "连接出错",
                                icon: "none"
                            });
                        }
                    });
                } else wx.showToast({
                    title: a.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                wx.hideLoading(), wx.showToast({
                    title: "连接出错",
                    icon: "none"
                });
            }
        }));
    },
    dTbindBgPickerChange: function(t) {
        var o = this;
        this.setData({
            "dtTextConfig.bgcolor": o.data.bgObColorArray[t.detail.value]
        });
    },
    dTbindFontCoPickerChange: function(t) {
        var o = this;
        this.setData({
            "dtTextConfig.color": o.data.fontVaColorArray[t.detail.value]
        });
    },
    dTbindFontPickerChange: function(t) {
        this.setData({
            "dtTextConfig.font": t.detail.value
        });
    },
    dTbindPlayTimeChange: function(t) {
        console.log(t), this.setData({
            "dtTextConfig.time": t.detail.value
        });
    },
    copyAppName: function() {
        wx.setClipboardData({
            data: "文字图片制作器",
            success: function(t) {
                wx.showToast({
                    title: "已复制"
                });
            }
        });
    },
    inputText: function(t) {
        this.setData({
            "textConfig.text": t.detail.value
        });
    },
    dTinputText: function(t) {
        this.setData({
            "dtTextConfig.text": t.detail.value
        });
    },
    bindFontCoPickerChange: function(t) {
        var o = this;
        this.setData({
            "textConfig.color": o.data.fontVaColorArray[t.detail.value]
        });
    },
    bindFontPickerChange: function(t) {
        this.setData({
            "textConfig.font": t.detail.value
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: "文字表情包制作，一键制作纯文字、动态、滚动、弹幕文字表情包",
            path: "pages/textmaker/textmaker"
        };
    }
});